<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>computed</title>
</head>
<body>

<div id="app">
  <h2>总价格：{{totalPrice}}</h2>
</div>
<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: '你好',
      books: [
        {id: 110, name: 'Java入门', price: 119},
        {id: 111, name: 'Python入门', price: 120},
        {id: 112, name: 'JS入门', price: 121},
        {id: 113, name: 'Vue入门', price: 122}
      ]
    },
    computed: {
      totalPrice: function () {
        let totalPrice = 0
        for (let i in this.books){
          totalPrice += this.books[i].price
        }
        return totalPrice

      }
    }

  })
</script>
</body>
</html>
